/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.postbar.util;

import static cn.ac.iie.di.postbar.server.PostLtStartUp.serverPath;
import org.apache.log4j.Logger;

/**
 *
 * @author Administrator
 */
public class DeDuplication {
    
    static private final Logger logger = Logger.getLogger(DeDuplication.class.getName());
    
    public static String[] deduplication(String content) {
        String response = "";
        boolean flag = false;
        while (true) {
            for (int re = 0; re < serverPath.length; re++) {
                try {
                    response = org.apache.http.client.fluent.Request.Post(serverPath[re])
                            .bodyByteArray(content.getBytes()).socketTimeout(1800000).connectTimeout(1800000)
                            .execute().returnContent().asString();
                    if (response != null) {
                        flag = true;
                        break;
                    }
                } catch (Exception e) {
                    logger.error("deduplicate failed,cause " + e.getMessage(), e);
                }
                logger.info("this ip[" + serverPath[re] + "] deduplicate failed, try next one.");
            }
            if (flag) {
                break;
            }
        }
        return response.split("\\n");
    }
}
